/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package com.lineage.server.model.skill.executor;

import com.lineage.server.model.L1Character;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.skill.L1SkillExecutor;
import com.lineage.server.packetserver.S_ServerMessage;
import com.lineage.server.utils.Random;

/**
 * Class <code>WeaponBreak</code> 法师魔法:坏物术 (32/0/1).
 * 在一定的机率损害目标的武器，损害程度依施法者的魔法等级而有所不同（每次使用增加10点邪恶值）
 * 
 * @author jrwz
 * @version 2012-7-24下午08:36:17
 * @see com.lineage.server.model.skill.executor
 * @since JDK1.7
 */
public final class WeaponBreak extends L1SkillExecutor {

    /**
     * 取得实例.
     * 
     * @return 实例
     */
    public static L1SkillExecutor get() {
        return new WeaponBreak();
    }

    /** 法师魔法:坏物术 (32/0/1). */
    private WeaponBreak() {
    }

    @Override
    public void execute(final L1Character user, final L1Character cha,
            final L1Character target, final int targetID, final int skillId,
            final int getBuffIconDuration) {
        if (cha instanceof L1PcInstance) {
            final L1PcInstance pc = (L1PcInstance) cha;
            final L1ItemInstance weapon = pc.getWeapon();
            if (weapon != null) {
                final int weaponDamage = Random.nextInt(user.getInt() / 3) + 1;
                pc.sendPackets(new S_ServerMessage(268, weapon.getLogName())); // \f1你的%0%s坏了。
                pc.getInventory().receiveDamage(weapon, weaponDamage);
            }
        } else if (cha instanceof L1NpcInstance) {
            final L1NpcInstance npc = (L1NpcInstance) cha;
            npc.setWeaponBreaked(true);
        }
    }

    @Override
    public void stop(final L1Character cha, final int skillId) {
        // TODO Auto-generated method stub
    }
}
